package com.byp.java_sport.model;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> implements Serializable {
    /**
     * 响应码
     */
    private int code;

    /**
     * 相应的消息
     */
    private String msg;
    /**
     * 响应结果
     */
    private T data;


    public Result(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(String msg, T data) {
        this.msg = msg;
        this.data = data;
    }
    public static <T> Result<T> success() {
        return new Result<>(200, "成功");
    }
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "成功",data);
    }
    public static <T> Result<T> success(String msg) {
        return new Result<>(200, msg);
    }
    public static <T> Result<T> success(String msg, T data) {
        return new Result<>(200, msg,data);
    }

    public static <T> Result<T> error() {
        return new Result<>(500, "失败");
    }

    public static <T> Result<T> error(String msg) {
        return new Result<>(500, msg);
    }

    public static <T> Result<T> error(int code,String msg) {
        return new Result<>(500, msg);
    }
    public static <T> Result<T> error(int code,String msg,T data) {
        return new Result<>(500, msg,data);
    }
}
